import redis
from secret import *

# 建立redis链接
redis_con = redis.StrictRedis(host=redis_ip,password=redis_passwd ,port=redis_port, db=2)


def del_ban_ip(ip):
    # 获取redis中2号数据库的所有key
    try:
        ban_ip = redis_con.delete(ip)
        return True, ""
    except Exception as e:
        return False, e


if __name__ == "__main__":
    ban_ips = del_ban_ip()
    print("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print(f"共封禁{len(ban_ips)-1}个ip地址\n")
    for each in ban_ips:
        print("%4s\t%16s\t%s" % (ban_ips.index(each), each[0], each[1]), end="\n")
    print("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
